package com.bizframework.security.service.impl;

import com.bizframework.security.domain.dao.UserDao;
import com.bizframework.security.domain.entity.User;
import com.bizframework.security.service.AuthenticationService;

public class AuthenticationServiceImpl implements AuthenticationService {

	private UserDao userDao;
	
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	
	public void authenticate(String userName, String password) throws Exception {
		User user = userDao.getByUserName(userName);
		
		if (user != null) {
			if (!user.getPassword().equals(password)) {
				throw new Exception("用户名和密码不匹配。");
			}
		}
		else {
			throw new Exception("用户不存在。");
		}
	}
}
